var app = getApp()
var {formatDate} = require('../../../utils/util')

Page({
  data: {},
  onLoad: function () {
    app.showLoading()
    this.loadMaiDian()
  },

  loadMaiDian: function () {
    if (app.tokenIsValid() === false) {
      app.getUserToken()
      setTimeout(() => {
        this.loadMaiDian()
      }, 100)
      return
    }
    var url = '/silo/h5/2209.json'
    var params = {
      auth: app.globalData.authToken
    }
    app.request(url, params).then(this.loadUserinfoCallback.bind(this))
  },
  loadUserinfoCallback: function (res) {
    app.hideLoading()

    var logs = res.data.logs
    for (var i = 0; i < logs.length; i++) {
      logs[i].createTime = formatDate(logs[i].createTime, 'yyyy-MM-dd')
    }

    this.setData({
      logs: logs
    })
  }
})
